import request from '@/utils/request'

const blog = {
  articles: '/articles',
  article: '/articles/{:id}',
  articlePub: '/articles/{:id}/publish',
  categories: '/categories',
  category: '/categories/{:id}',
  tags: '/tags',
  tag: '/tags/{:id}'
}

export default blog

export function getArticles (parameter) {
  return request({
    url: blog.articles,
    method: 'get',
    params: parameter
  })
}

export function newArticle (data) {
  return request({
    url: blog.articles,
    method: 'post',
    data: data
  })
}

export function getArticle (id) {
  return request({
    url: blog.article.replace('{:id}', id),
    method: 'get'
  })
}

export function editArticle (id, data) {
  return request({
    url: blog.article.replace('{:id}', id),
    method: 'put',
    data: data
  })
}

export function pubArticle (id) {
  return request({
    url: blog.articlePub.replace('{:id}', id),
    method: 'post'
  })
}

export function getCategories () {
  return request({
    url: blog.categories,
    method: 'get'
  })
}

export function getCategory (id) {
  return request({
    url: blog.category.replace('{:id}', id),
    method: 'get'
  })
}

export function editCategory (id, data) {
  return request({
    url: blog.category.replace('{:id}', id),
    method: 'put',
    data: data
  })
}

export function delCategory (id) {
  return request({
    url: blog.category.replace('{:id}', id),
    method: 'delete'
  })
}

export function getTags () {
  return request({
    url: blog.tags,
    method: 'get'
  })
}

export function getTag (id) {
  return request({
    url: blog.tag.replace('{:id}', id),
    method: 'get'
  })
}

export function editTag (id, data) {
  return request({
    url: blog.tag.replace('{:id}', id),
    method: 'put',
    data: data
  })
}

export function delTag (id) {
  return request({
    url: blog.tag.replace('{:id}', id),
    method: 'delete'
  })
}
